package com.example.role.auth;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * @BelongsProject: jw
 * @BelongsPackage: com.wn.auth
 * @Author: tkrestnhmt
 * @CreateTime: 2020-07-08 14:29
 * @Description:
 */

public class CookieUtil {

    public static void resposeCookie(String token, Integer time, HttpServletResponse response){
        Cookie cookie = new Cookie("token", token);
        //设置cookie有效期为1800秒
        cookie.setMaxAge(time);
        //设置cookie适用的域(一级域名)
        cookie.setDomain("jf.com");
        //允许一级域名下的所有请求都能对cookie进行读写
        cookie.setPath("/");
        //后端向前端写入cookie
        response.addCookie(cookie);
    }
}
